﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;

namespace Qianke.Core.Common
{
    public static class ConfigurationExtensions
    {

        public static void ConfigureFromConfiguration<TOptions>(this IServiceCollection services)
            where TOptions : class
        {
            var configuration = services.GetConfiguration();
            services.Configure<TOptions>(options =>
            {
                configuration.Bind(typeof(TOptions).Name, options);
            });
        }

        public static void ConfigureFromConfiguration<TOptions>(this IServiceCollection services, Action<TOptions> actionOptions)
            where TOptions : class
        {
            var configuration = services.GetConfiguration();
            services.Configure<TOptions>(options =>
            {
                configuration.Bind(typeof(TOptions).Name, options);
                actionOptions(options);
            });
        }


    }
}
